from redis import StrictRedis
import logging

class Config(object):
    """项目配置类"""

    # 设置secret_key混淆字符串
    SECRET_KEY = "og6vuWUhFDDQGhfxGldSCHJjy3pk1eqwkpjC4Ga79NVNUGDgx/NikbMkkI52qsPTTmdGsadBd63sEJSMydTzog=="

    # mysql数据库的配置
    SQLALCHEMY_DATABASE_URI = "mysql://root:cq@127.0.0.1:3306/information"
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    # 当视图函数的数据库对象发送改变，默认自动帮助其保存到数据库
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True

    # redis数据库的配置
    REDIS_IP = "127.0.0.1"
    REDIS_PORT = 6379

    # session的配置
    # 指明session存储到redis数据库
    SESSION_TYPE = "redis"
    # 创建redis对象，具体把session存储到redis里面
    SESSION_REDIS = StrictRedis(host=REDIS_IP, port=REDIS_PORT)
    # 存储session的时候session_id需要签名处理（加密）
    SESSION_USE_SIGNER = True
    # 不需要永久存储
    SESSION_PERMANENT = False
    # 设置session过期时长
    PERMANENT_SESSION_LIFETIME = 86400 * 2



class DevelopmentConfig(Config):
    """开发环境的项目配置信息"""
    DEBUG = True
    # 设置日志级别
    LOG_LEVEL = logging.DEBUG


class ProductionConfig(Config):
    """线上环境的项目配置信息"""
    DEBUG = False
    # 设置日志级别
    LOG_LEVEL = logging.WARNING
    # SQLALCHEMY_DATABASE_URI = "mysql://root:cq@线上ip:3306/information"
    # REDIS_IP = "线上ip"


class TestingConfig(Config):
    """单元测试项目配置信息"""
    DEBUG = True
    # 测试代码出错了可以定位过去哪一行出错
    TESTING = True


config_dict = {
    "development": DevelopmentConfig,
    "production": ProductionConfig,
    "testing": TestingConfig
}